
 /**
 * UploadFileUtils.java.java.
 * User: BrianChen Date: 2012-3-16 下午01:03:23
 *
 * Copyright (c) 2009 Hewlett-Packard Development Company, L.P.
 * All rights reserved.
 */
package com.collapsar.core.util.file;

import java.util.List;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.collapsar.core.util.GlobalConfig;


/**
 * <pre>
 * REVISIONS: 
 * Version 	Date 		Author 			Description
 * ------------------------------------------------------------------- 
 * 1.0 		2012-3-16 	BrianChen 	1. Created this class. 
 * </pre>
 * 
 * @author BrianChen
 * @date 2012-3-16 下午01:03:23
 * @version 1.0
 * @see
 * 
 */
public class FileUploadUtils {
	private static final Logger logger = LoggerFactory.getLogger(FileUploadUtils.class);
	private static final List<String> FILEUPLOAD_ALLOWED_EXTENS = GlobalConfig.getAllowedFileExts();
	private static final List<String> FILEUPLOAD_DENIED_EXTENS = GlobalConfig.getDeniedFileExts();
	private static final long FILEUPLOAD_MAX_ALLOWED_FILE_SIZE = GlobalConfig.getAllowedMaxFileSize();
	private static final String FILEUPLOAD_REPOSITORY_PATH = GlobalConfig.getRepositoryPath();
	
	
	/**
	 * 验证上传文件的类型，大小，格式等信息
	 * @param fileName
	 * @return
	 */
	private static boolean validateFile(String fileName){
		boolean accept = false;
		String fileExt = FilenameUtils.getExtension(fileName);
		if(FILEUPLOAD_ALLOWED_EXTENS != null){
			logger.info("#####FILEUPLOAD_ALLOWED_EXTENS={}", FILEUPLOAD_ALLOWED_EXTENS);
			for(String extStr : FILEUPLOAD_ALLOWED_EXTENS){
				if(StringUtils.equalsIgnoreCase(extStr, fileExt)){
					accept = true;
					break;
				}
			}
		}else if(FILEUPLOAD_DENIED_EXTENS != null){
			logger.info("#####FILEUPLOAD_DENIED_EXTENS={}", FILEUPLOAD_DENIED_EXTENS);
			for(String extStr : FILEUPLOAD_DENIED_EXTENS){
				if(StringUtils.equalsIgnoreCase(extStr, fileExt)){
					accept = false;
					break;
				}
			}
		}
		return accept;
	}

}

